package com.myproject.thread.interrupt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InterruptState3 {

    private static final Logger logger = LoggerFactory.getLogger(InterruptState3.class);

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread() {

            @Override
            public void run() {
                try {
                    Thread.currentThread().setName("test");
                    logger.info("thread-start");
                    for (int i = 0; i < 10; i++) {
                        for (int j = 0; j < 1000000000; j++) {
                            Math.sin(0.34334);
                        }
                        logger.info("i={}", i);
                    }
                    logger.info("thread-end");
                } catch (Exception e) {
                    logger.info("Exception,interrupted={}", Thread.interrupted(), e);
                } finally {
                    logger.info("finally~~,interrupted={}", Thread.interrupted());
                }
            }
        };
        thread.start();
        Thread.sleep(1000);
        logger.info("start interrupt thread!");
        thread.interrupt();

        thread.join();
        logger.debug("end");

        System.out.println(thread.getClass().getName());
    }
}
